package com.sangmo.fts.api.student;


import com.sangmo.boot.framework.api.utils.ApiResponse;
import com.sangmo.boot.framework.common.security.meta.Access;
import com.sangmo.boot.framework.data.filter.PageResult;
import com.sangmo.boot.framework.data.json.ExtViewHelper;
import com.sangmo.boot.framework.plugin.dataview.data.DataViewPageSearch;
import com.sangmo.fts.basic.model.Notice;
import com.sangmo.fts.basic.service.NoticeService;
import com.sangmo.fts.teacher.model.Examination;
import com.sangmo.fts.teacher.service.ExaminationService;
import com.sangmo.fts.training.vo.LatestScoreView;
import com.sangmo.fts.training.model.Score;
import com.sangmo.fts.training.service.ScoreService;
import com.sangmo.fts.user.model.Account;
import com.sangmo.fts.user.service.AccountService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.validation.Valid;
import java.util.HashMap;

@Controller
@RequestMapping("/student/v1")
public class StudentApi {

    @Autowired
    private AccountService accountService;

    @Autowired
    private ExaminationService examinationService;

    @Autowired
    private NoticeService noticeService;

    @Autowired
    private ScoreService scoreService;

    @Access("account:read")
    @PostMapping(value = "/account")
    public @ResponseBody
    ApiResponse<Account> getAccountInfo() {
        return ApiResponse.make(accountService.getAccountInfo());
    }


    @PostMapping("/score/latest")
    public @ResponseBody ApiResponse<LatestScoreView> latestScore() {
//        ExtViewHelper.setGroup("Score.search", 1);
        return ApiResponse.make(scoreService.latestScore());
    }

//    @Access("score:read")
    @PostMapping("/score/search")
    public @ResponseBody ApiResponse<PageResult<Score>> searchScore(@RequestBody @Valid DataViewPageSearch<HashMap> ps) {
        ExtViewHelper.setGroup("Score.search", 1);
        return ApiResponse.make(scoreService.searchForStudent(ps));
    }

//    @Access("examination:read")
    @PostMapping("/examination/search")
    public @ResponseBody ApiResponse<PageResult<Examination>> searchExamination(@RequestBody @Valid DataViewPageSearch<HashMap> ps) {
        return ApiResponse.make(examinationService.searchForStudent(ps));
    }

//    @Access("notice:read")
    @PostMapping("/notice/search")
    public @ResponseBody ApiResponse<PageResult<Notice>> searchNotice(@RequestBody @Valid DataViewPageSearch<HashMap> ps) {
        return ApiResponse.make(noticeService.searchForStudent(ps));
    }



}


